clear
set more off


* Descriptive evidence, Graphs : Marriages, Gains and Singles


use "$data\gains_marriage_nativehusband.dta" , clear 
keep year phixy nm EUII
gen type = 1

append using  "$data\gains_marriage_nativewife.dta" 
replace type= 2 if type==.
lab define typel  1 "hetw" 2 "heth"
lab var type typel

rename EUII euii
gen eui =.
replace eui=1 if euii==1 
replace eui=2 if euii==2
replace eui=3 if euii==3
replace eui=4 if euii==4
replace eui=5 if euii>=5
lab define euil 0 "Italians" 1 "EU15" 2 "EU2004" 3 "EU2007" 4 "Rest of Europe" 5 "All other countries" 
lab values eui euil
collapse (sum) nm , by(year eui)
gen nm980=nm if year==1998
bys eui: egen nm98=mean(nm980)
gen nmrate=nm/nm98
drop nm98*

* Include marriages of natives

append using "$data\homogamous_italian.dta" 
tab eui
sort eui year

********************************************************************************
*  Figure 5: Panel a. Marriage rates
*  Marriages and separations, homogamous native couples and heterogamous couples formed by natives and immigrants, by area of origin of the foreign spouse

gen cc1=5 if year>=2002 & year<=2004.5
gen cc2=5 if year>=2005 & year<=2007
gr twoway (area cc1 year , bcolor(gs15)) ///
          (area cc2 year , bcolor(gs14)) ///
          (scatter nmrate year if eui==0, c(l) lc(lavender) mc(lavender)  m(S) msize(small)) ///
          (scatter nmrate year if eui==1, c(l) lc(dkorange) mc(dkorange) lpattern(dash)  m(S) msize(small)) ///
          (scatter nmrate year if eui==2, c(1) lc(cranberry) mc(cranberry) m(D) msize(small) lw(medium) ) ///
          (scatter nmrate year if eui==3, c(1) lc(dknavy) mc(dknavy) m(O) msize(small) lw(medium)) ///
  		  (scatter nmrate year if eui==4, c(l) lc(forest_green) mc(forest_green)  lpattern(dot) m(T) msize(small)) ///
		  (scatter nmrate year if eui==5, c(l) lc(black) mc(black)  lpattern(dash) m(X) ), ///
graphregion(color(white)) ///
legend(label(3 "Italian") label(4 "EU15") label(5 "EU2004") label(6 "EU2007") label(7 "Rest of Europe") label(8 "All other countries") order(5 6 7 3 4 8) r(2)  size(*0.7) region(lcolor(none)) ) ///
xsca(r(1998 2012)) xlab(1998(2)2012 , labs(small)) ///
ysca(r(0 5)) ylab(0(1)5 , labs(small) grid) xtitle("", size(*0.2))
gr save   "$output\graph_marriages.gph" , replace
gr export "$output\graph_marriages.pdf" , replace




use "$data\gains_marriage_nativehusband.dta" , clear

codebook phixy
codebook Fsingle
codebook Msingle
gen eui =.
replace eui=1 if euii==1 
replace eui=2 if euii==2
replace eui=3 if euii==3
replace eui=4 if euii==4
replace eui=5 if euii>=5
lab values eui euil
collapse (sum) Msingle Fsingle nm, by(eui year)
gen phi = ln((nm^2)/(Msingle*Fsingle))
tab eui, gen(eu)
rename eu1 EU15
rename eu2 EU2004
rename eu3 EU2007
rename eu4 Rest_of_Europe
rename eu5 All_other_countries

********************************************************************************
*  Appendix Figure A4: Panel a. Native husband - foreign wife
*  Singles, marriages, and gains from marriage by area of origin, 1998-2012

gen c1 =-15 if  year>=2002 & year<=2004.5
gen c2 =-15 if  year>=2005 & year<=2007
foreach var in EU2004 EU2007 EU15 Rest_of_Europe All_other_countries   {
tab `var'
graph tw (area c1 year , bcolor(gs15)) ///
         (area c2 year , bcolor(gs14)) ///
         (scatter phi year, c(l) yaxis(1) lw(medthick) m(D) lcolor(edkblue) mcolor(edkblue) ) ///
         (scatter nm year, c(l) yaxis(2) m(O) lcolor(cranberry) mcolor(cranberry) ) ///
		 (scatter Fsingle year, c(l) yaxis(2) m(T) lcolor(dkgreen) mcolor(dkgreen) ) if `var'==1 , ///
		 graphregion(color(white)) ///
		 legend(order(3 "Gains from marriage" 4 "Number of marriages" 5 "Unmatched single females") r(1) size(*0.9) region(lcolor(none))) ///
 		 xsca(r(1998(2)2012)) xtick(1998(2)2012)  ///
		 xlab( 1998(2)2012 , labs(small) angle(30)) ///
		 ysca(r(-15 -9)) ylab(-15(1)-9) ylab( , axis(1) labs(small) grid) ylab( , axis(2) labs(small)) ///
		 title("`var'", color(black)) xtitle("") ///
		 ytitle( "Gains from marriage"  " ", axis(1) size(*0.9)) ytitle(" " "Number of marriages" "Unmatched single females", axis(2) size(*0.9)) 
graph save "$output\graph_gains_singles_marriages_`var'_foreignfemales.gph"	, replace	 
graph export "$output\graph_gains_singles_marriages_`var'_foreignfemales.pdf"	, replace	 

}

********************************************************************************
*  Figure 6: Panel a. Native husband - foreign wife
*  Gains from marriage, heterogamous couples formed by natives and immigrants, by area of origin of the foreign spouse			
  
graph tw (area c1 year , bcolor(gs15)) ///
         (area c2 year , bcolor(gs14)) ///
         (scatter phi year if EU15==1, c(l) lc(dkorange) mc(dkorange) lpattern(dash)  m(S) msize(small) ) ///
		 (scatter phi year if EU2004==1, c(1) lc(cranberry) mc(cranberry) m(D) msize(small) ) ///
         (scatter phi year if EU2007==1, c(1) lc(dknavy) mc(dknavy) m(O) msize(small) ) ///
         (scatter phi year if Rest_of_Europe==1, c(l) lc(forest_green) mc(forest_green)  lpattern(dot) m(T) msize(small)) ///
         (scatter phi year if All_other_countries==1, c(l) lc(black) mc(black)  lpattern(dot) m(X) msize(small)), ///
         graphregion(color(white)) legend(label(3 "EU15") label(4 "EU2004") label(5 "EU2007")  label(6 "Rest of Europe") label(7 "All other countries")  order(4 5 7 3 6) r(1)  size(*0.7) region(lcolor(none)) ) ///
 		 xsca(r(1998(2)2012)) xtick(1998(2)2012) xlab( 1998(2)2012 , labs(small) angle(30)) ///
		 ysca(r(-15 -9)) ylab(-15(1)-9, labs(small) grid)  ///
		 ytitle( "Gains from marriage"  " ", size(*0.9)) xtitle("") 
graph save "$output\graph_gains_foreignfemales.gph"	, replace	 
graph export "$output\graph_gains_foreignfemales.pdf"	, replace	 




use "$data\gains_marriage_nativewife.dta" , clear

codebook phixy
codebook Fsingle
codebook Msingle
gen eui =.
replace eui=1 if euii==1 
replace eui=2 if euii==2
replace eui=3 if euii==3
replace eui=4 if euii==4
replace eui=5 if euii>=5
lab values eui euil
collapse (sum) Msingle Fsingle nm, by(eui year)
gen phi = ln((nm^2)/(Msingle*Fsingle))
tab eui, gen(eu)
rename eu1 EU15
rename eu2 EU2004
rename eu3 EU2007
rename eu4 Rest_of_Europe
rename eu5 All_other_countries

********************************************************************************
*  Appendix Figure A4: Panel b. Native wife - foreign husband 
*  Singles, marriages, and gains from marriage by area of origin, 1998-2012

gen c1=-18.5 if  year>=2002 & year<=2004.5
gen c2=-18.5 if  year>=2005 & year<=2007
foreach var in EU2004 EU2007 EU15 Rest_of_Europe All_other_countries   {

tab `var'
graph tw (area c1 year , bcolor(gs15)) ///
         (area c2 year , bcolor(gs14)) ///
         (scatter phi year, c(l) yaxis(1) lw(medthick) m(D) lcolor(edkblue) mcolor(edkblue) ) ///
         (scatter nm year, c(l) yaxis(2) m(O) lcolor(cranberry) mcolor(cranberry) ) ///
		 (scatter Msingle year, c(l) yaxis(2) m(T) lcolor(dkgreen) mcolor(dkgreen) ) if `var'==1 , ///
		 graphregion(color(white)) ///
		 legend(order(3 "Gains from marriage" 4 "Number of marriages" 5 "Unmatched single males") r(1) size(*0.9) region(lcolor(none))) ///
 		 xsca(r(1998(2)2012)) xtick(1998(2)2012)  ///
		 xlab( 1998(2)2012 , labs(small) angle(30)) ///
		 ysca(r(-18 -12)) ylab(-18(1)-12 ,  labs(small) grid) ///
		 title("`var'", color(black)) xtitle("") ///
		 ytitle( "Gains from marriage"  " ", axis(1) size(*0.9)) ytitle(" " "Number of marriages" "Unmatched single males", axis(2) size(*0.9)) 
graph save "$output\graph_gains_singles_marriages_`var'_foreignmales.gph"	, replace	 
graph export "$output\graph_gains_singles_marriages_`var'_foreignmales.pdf"	, replace	 

}
  
********************************************************************************
*  Figure 6: Panel b. Native wife - foreign husband
*  Gains from marriage, heterogamous couples formed by natives and immigrants, by area of origin of the foreign spouse			
			  
graph tw (area c1 year , bcolor(gs15)) ///
         (area c2 year , bcolor(gs14)) ///
         (scatter phi year if EU15==1, c(l) lc(dkorange) mc(dkorange) lpattern(dash)  m(S) msize(small) ) ///
		 (scatter phi year if EU2004==1, c(1) lc(cranberry) mc(cranberry) m(D) msize(small) ) ///
         (scatter phi year if EU2007==1, c(1) lc(dknavy) mc(dknavy) m(O) msize(small) ) ///
		 (scatter phi year if Rest_of_Europe==1, c(l) lc(forest_green) mc(forest_green)  lpattern(dot) m(T) msize(small)) ///
		 (scatter phi year if All_other_countries==1, c(l) lc(black) mc(black)  lpattern(dash) m(X) ), ///
         graphregion(color(white)) legend(label(3 "EU15") label(4 "EU2004") label(5 "EU2007")  label(6 "Rest of Europe") label(7 "All other countries")  order(4 5 6 3 7) r(1)  size(*0.7) region(lcolor(none)) ) ///
 		 xsca(r(1998(2)2012)) xtick(1998(2)2012) xlab( 1998(2)2012 , labs(small) angle(30)) ///
		ysca(r(-18 -12)) ylab(-18(1)-12 ,  labs(small) grid) ///
		 ytitle( "Gains from marriage"  " ", size(*0.9)) xtitle("") 
graph save "$output\graph_gains_foreignmales.gph"	, replace	 
graph export "$output\graph_gains_foreignmales.pdf"	, replace	 






